/*
 * La clase mapa.
 *
 * This is part of the game The Rooms
 * Copyright (C) 2010  Elvio Sarquis
 *
 * Get the GNU GPL v3 in http://www.gnu.org/licenses/
 */

package rooms;

/**
 *
 * @author dask
 */
public class Map {

    private int map[][] = {
        {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1},
        {1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1},
        {1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1},
        {1 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,1 ,1 ,2 ,1 ,1},
        {1 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1},
        {1 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,2 ,0 ,0 ,0 ,1},
        {1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,3 ,1 ,1},
        {1 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,1 ,0 ,0 ,0 ,1},
        {1 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,1 ,0 ,0 ,0 ,1},
        {1 ,1 ,3 ,1 ,1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 ,1 ,1},
        {1 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1},
        {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1}};

    private final int MAXX;
    private final int MAXY;

    private int bumpmap[][];

    public Map(){
        MAXX = map.length;
        MAXY = map[1].length;
        bumpmap = new int[MAXX][MAXY];

    }

    public Map(String[] newmap, int x, int y){
        MAXX = x;
        MAXY = y;
        map = new int[MAXX][MAXY];
        bumpmap = new int[MAXX][MAXY];
        for(int i = 0; i<MAXX; i++)
        for(int j = 0; j<MAXY; j++){

            map[i][j] = (int)newmap[j].charAt(i)-48;
        }
    }

    public Map(int[][] newmap, int x, int y){
        MAXX = x;
        MAXY = y;
        map = new int[MAXX][MAXY];
        bumpmap = new int[MAXX][MAXY];
        
        map=newmap;
    }

    public void change(int x,int y,int to){
     
        map[x][y]=to;
    }

    public void refactor(Character[] ch){

        
        for(int i = 0; i<MAXX;i++)
        for(int j = 0; j<MAXY;j++){

            switch(map[i][j]){

                case C.FLOOR: bumpmap[i][j] = 0;break;
                case C.WALL: bumpmap[i][j] = 1;break;
                case C.CDOOR: bumpmap[i][j] = 2;break;
                case C.ODOOR: bumpmap[i][j] = -3;break;
                case C.DOWNS: bumpmap[i][j] = -1;break;
                case C.UPS: bumpmap[i][j] = -2;break;
                case C.NO: bumpmap[i][j] = 1;break;
                default: bumpmap[i][j] = 1;
            }
        }

        for(int i = 0; i < ch.length; i++){
            bumpmap[ch[i].getX()][ch[i].getY()] = ch[i].getId() + 10;
        }

    }

    public int[][] getMap(){
        return map;
    }

    public int[][] getBumpMap(){
        return bumpmap;
    }

    public int getMapX(){
        return MAXX;
    }

    public int getMapY(){
        return MAXY;
    }

    public int getMapPoint(int x, int y){
        if(x < 0 || y < 0 || x >= MAXX  || y >= MAXY){
            return C.NO;
        }else{
            return map[x][y];
        }
    }

    public int getBumpMapPoint(int x, int y){
        if ((x > MAXX) || (y>MAXY) || (x<0) ||(y<0)){
            return 1;
        } else{
            return bumpmap[x][y];
        }
    }
}